// 请求接口
import { getList ,getInfo,deleteStudent,addStudent ,editStudent ,isEnableStudent} from '@/api/student'

import Qs from 'qs'
// 重设路由表

// 默认的用户状态
const getDefaultState = () => {
  return {
    AllStudent:""
  }
}

const state = getDefaultState()

const mutations = {
  SET_ALLSTUDENT: (state,AllStudent) => {
    state.AllStudent = AllStudent
  },

}

const actions = {

  // 获取学生列表信息
  async getList({commit},serchForm) {
    let res = await getList(serchForm);
    return res
  },
  // 删除学生信息
  async deleteStudent({},id) {
    let res = await deleteStudent(id);
    return res
  },
  // 添加学生信息
  async addStudent({},studentForm) {
    // console.log(studentForm);
    const res = await addStudent(studentForm);
    return res
  },
  // 添加单个学生信息
  async getInfo({},id) {
    const res = await getInfo(id);
    return res
  },
  // 修改单个学生信息
  async editStudent({},studentInfo) {
    const res = await editStudent(studentInfo.id,studentInfo);
    return res
  },
  async isEnableStudent({},info){
    // 拼接字符串后端使用参数来接收 不是请求题
    let params = Qs.stringify(info)
    const res = await isEnableStudent(info.id,params)
    return res
  }
  
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}

